package top.itlir.edc.service.impl;

import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.itlir.edc.dao.WayBillRepository;
import top.itlir.edc.domain.WayBill;
import top.itlir.edc.index.WayBillIndexRepository;
import top.itlir.edc.service.IWayBillService;

@Service
@Transactional
public class WayBillServiceImpl implements IWayBillService {
	
	@Autowired
	private WayBillRepository wayBillRepository;
	
	// 添加 索引注解
	@Autowired
	private WayBillIndexRepository wayBillIndexRepository;

	@Override
	public void save(WayBill model) {
		wayBillRepository.save(model);
		wayBillIndexRepository.save(model);
	}

	@Override
	public Page<WayBill> pageQuery(Specification<WayBill> spec,
			Pageable pageable) {
		return wayBillRepository.findAll(spec, pageable);
	}
	
	@Override
	/**
	 * QueryBuilder 查询方法
	 */
	public Page<WayBill> pageQuery(QueryBuilder builer, Pageable pageable) {
		return wayBillIndexRepository.search(builer, pageable);
	}

}
